package com.validate.fluentvalidator;


import com.validate.advocatevalidator.ValidatorsResult;
import com.validate.fluentvalidator.reflection.FieldReflection;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.List;

/**
 * 校验工具类
 */
public class Validator<T> {

	private int allnext = -1;

	public Validator(){
		TypeVariable[] tValue = FieldReflection.class.getTypeParameters();
		Type t = getClass().getGenericSuperclass();
		if(t.getTypeName().equals("com.validate.fluentvalidator.Validator<java.util.List<com.validate.advocatevalidator.ValidatorsResult>>")){
			allnext = 1;
		}
		if(t.getTypeName().equals("com.validate.fluentvalidator.Validator<com.validate.advocatevalidator.ValidatorsResult>")){
			allnext = 0;
		}
	}

	private List<ValidatorGroup> validatorGroups = new ArrayList<ValidatorGroup>();

	public T Result(Object var1){
		return Result(var1,new String[]{});
	}

	public ValidatorGroup on(boolean sic){
		ValidatorGroup validatorGroup = new ValidatorGroup(sic);
		validatorGroups.add(validatorGroup);
		return validatorGroup;
	}

	private T Result(Object var1,String[] groups){
		FieldReflection field = new FieldReflection();
		if(allnext == 1){
			return (T)field.reflection(var1,groups,true);
		}
		if(allnext == 0){
			return (T)field.reflection(var1,groups,false);
		}
		try {
			throw new IllegalAccessException("T Is Error");
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}

}
